const { get_others } = require('../../Class/GetOthers.js');
const getOthers = new get_others();
Page({

  data: {
    bgflag: true,
    flag:false,
    flag1: false
  },
  open() {
    this.setData({
      flag: !this.data.flag,
      flag1: true
    })
  },
  GoRead(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/e-courses/read/read?id='+id 
    })
  },
  userInput(e) {
    const user_content = e.detail.value.trim();
    if (!user_content) {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      });
      return;
    }
    const search_result = this.data.pdf
      .filter(item => item.title.includes(user_content))
      .map(item => item.id);
    if (search_result.length > 0) {
      console.log(search_result);
      wx.navigateTo({
        url: '/pages/e-courses/search/search?id=' + JSON.stringify(search_result) + '&search=' + user_content,
      });
    } else {
      wx.showModal({
        content: '抱歉！未检索到您想查找的书籍',
        showCancel: false
      });
    }
  },
  
  async onLoad(options) {
    wx.showLoading({
      title: '数据正在加载中...',
      mask:true
    })
    const result = await getOthers.Get_TXT()
    this.setData({
      pdf:result
    })
    wx.hideLoading()
  },

  changebg(e){
    this.setData({bgflag : true})
  }
})